<template>
	<!-- //微信小程序 ：style="[]" 要用数组的形式 -->
	<!-- //微信小程序 ：style="[]" 要用数组的形式 -->
	<view class="custom-page" :style="[customPage.page]">

		<!-- navgation -->
		<view class="custom-navigation-bar" :style="[customPage.nav]">
			<view class="custom-navigation-inner" style="justify-content: flex-start;">
				<view class="l_back" @tap.stop="OnBack">
					<image style="width: 40rpx;height:40rpx" src="@/static/icons/left_arrow.png"></image>
				</view>
				<view class="navigation-title" style="color: #FFFFFF;">区域资源</view>

			</view>
		</view>
		<image class="page_bg" src="@/static/images/map/bg.jpg"></image>
		<!-- <view style="width: 100%;height: 160rpx;display: flex;align-items: center;justify-content: center;z-index:2">
			<view class="map_search_bg">
				<view class="map_search">
					<image class="map_search_icon" src="../../static/icons/search.svg"></image>
					<input class="map_search_input" v-model="params.filter.key" placeholder="请输入搜索内容" placeholder-class="map_search_input_place" />
					<view class="map_search_line"></view>
					<view class="map_search_btn" @tap.stop="pageRefresh">搜索</view>
				</view>
			</view>
		</view> -->
		<view class="flex-column l_page_content">
			<!-- <map :style="{width:mapConfig.width+'px',height:mapConfig.height+'px'}"></map> -->
			<view class="l_list">
				<cc-pullScroolView :height="mapConfig.height+'px'" class="pullScrollView" ref="pullScroll"
					:back-top="true" :pullDown="pullDown">

					<!-- 
					<view class="l_list_item" @tap.stop="GoDetail(i)" :key="idx" v-for="(i,idx) in list">
						<view class="l_list_h" >{{i.name}}</view>
						<view class="l_list_h2" >{{i.file}}</view>
					</view> -->

					<view class="l_list_item" :key="idx" v-for="(i,idx) in list"> 
						<view class="l_list_header">
							<view class="flex-row">
								<image class="l_list_icon" style="height: 26rpx;" src="../../static/icons/zy.svg">
								</image>
								<view class="l_list_h">{{i.name}}</view>
							</view>
							<view class="l_list_h2"></view>
						</view>
						<view class="l_list_content">
							<view class="l_list_inner">
								<image class="l_list_icon" src="../../static/icons/cl.svg"></image>
								<view class="l_list_t">{{i.output}}</view>
							</view>
							<view class="l_list_inner">
								<image class="l_list_icon" src="../../static/icons/price.svg"></image>
								<view class="l_list_t">{{i.price}}</view>
							</view>
						</view>
					</view>


					<view class="l_empty" id="l_empty"></view>
				</cc-pullScroolView>
			</view>
		</view>
	</view>
</template>

<script>
	import Adpation from '@/library/platform/Adpation.js';
	import * as ResourcesApis from '@/network/apis/Resource.js';
	import * as OpenFile from '@/library/utils/openfile.js';
	export default {
		mixins: [Adpation],
		data() {
			return {
				ISSUBMIT: false,
				mapConfig: {
					width: 0,
					height: 0,
				},
				observer: null,
				params: {
					currentPage: 1,
					pageSize: 8,
					total: 0,
					filter: {
						key: ''
					},
				},
				list: [],
				// {
				// "id": 0,
				//       "name": "string",
				//       "output": "string",
				//       "price": "string",
				//       "revision": 0
				//   }
			}
		},
		onLoad() {
			this.SetConfig();
		},
		onShow() {
			this.pageRefresh();
		},
		onReady() {
			this.OnEmpty();
		},
		filters: {
			SubTime(val) {
				if (!val) return '--';
				if (typeof val == 'string') return val.substring(0, 10);
				else return val;
			}
		},
		methods: {
			OnBack() {
				if (this.ISSUBMIT) return;
				this.ISSUBMIT = true;
				uni.navigateBack();
				this.ISSUBMIT = false;
			},
			// 获取大小
			SetConfig() {
				const query = uni.createSelectorQuery().in(this);
				query.select('.l_list')
					.boundingClientRect(res => {
						console.log(res)
						if (res && res.width && res.height) {
							this.mapConfig.height = res.height;
							this.mapConfig.width = res.width;
						}
					})
					.exec();

			},
			GoDetail(e) {
				if (this.ISSUBMIT) return;
				this.ISSUBMIT = true;
				if (e && e.file) OpenFile.WatchFile(e.file);
				this.ISSUBMIT = false;
			},
			//页面刷新
			pageRefresh() {
				let self = this;
				this.$nextTick(() => {

					self.$refs.pullScroll.refresh();

				});
			},
			// 下拉刷新
			pullDown(pullScroll) {

				console.log('下拉刷新');
				this.list = [];
				this.params.currentPage = 1;
				this.GetListData(pullScroll);

			},
			async GetListData() {

				let self = this;

				let res = await ResourcesApis.getList(this.params);
				if (res && res.success) {
					this.params.total = res.data.total;
					this.list = [...this.list, ...res.data.list];
					// 如果是最后一页
					if (self.params.currentPage * self.params.pageSize >= self.params.total) {
						self.$refs.pullScroll.finish();

					} else {
						// 不是最后一页
						self.$refs.pullScroll.success();
					}
				} else {
					self.$refs.pullScroll.error();
				}




			},
			OnEmpty() {
				//创建曝光对象
				if (this.observer) {
					this.observer.disconnect();
				}
				this.observer = uni.createIntersectionObserver(this)
				console.log(this.observer)
				this.observer.relativeTo('.l_list').observe('#l_empty', (res) => {
				
					if (res.intersectionRatio>0&&this.list.length>0) {
							this.LoadMore();
					}
				})
			},
			// 上拉加载
			LoadMore() {
				// 数据全部加载完
				if (this.params.currentPage * this.params.pageSize >= this.params.total) {
					console.log('LoadMore ------------->');
				} else {
					// 显示加载中
					console.log('LoadMore ------------->');
					this.$refs.pullScroll.showUpLoading();
					this.params.currentPage++;
					this.GetListData();
				
				}

			},
		}
	}
</script>

<style>
	.page_bg {
		top: 0rpx;
		left: 0;
		position: fixed;
		height: 336rpx;
		width: 100vw;
		z-index: 1;
	}

	.l_page_content {
		margin-top: 30rpx;
		overflow-y: hidden;
		height: calc(100vh - var(--page-bottom) - var(--page-top) - 30rpx) !important;
		padding-top: 0 !important;
		background-color: transparent;
	}

	/* 搜索栏目 */
	.map_search_bg {
		width: 690rpx;
		height: 80rpx;
		border-radius: 8rpx;
		background-color: rgba(197, 210, 255, 0.50);
	}

	.map_search {
		width: 690rpx;
		height: 80rpx;
		border-radius: 8rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		padding: 12rpx 0 12rpx 42rpx;
	}

	.map_search_icon {
		flex-shrink: 0;
		width: 32rpx;
		height: 32rpx;
		margin-right: 20rpx;
	}

	.map_search_input {
		width: 470rpx;
		height: 56rpx;
		color: #FFFFFF;
		font-size: 26rpx;
	}

	.map_search_input_place {
		color: #FFFFFF;
		font-size: 26rpx;
	}

	.map_search_line {
		margin-left: 20rpx;
		flex-shrink: 0;
		width: 2rpx;
		height: 38rpx;
		background-color: #FFFFFF;
	}

	.map_search_btn {
		color: #FFFFFF;
		width: 90rpx;
		height: 80rpx;
		font-size: 26rpx;
		line-height: 80rpx;
		text-align: center;
	}



	/* 列表 */

	.pullScrollView {
		display: flex;
		flex-direction: column;

	}

	.l_list {
		width: 100%;
		height: 100%;
		overflow: hidden;
		overflow-y: scroll;
	}

	/* 列表项 */

	.l_list_item {
		width: 690rpx;
		box-sizing: border-box;
		min-height: 256rpx;
		margin: 0rpx 0 20rpx;
		display: flex;
		margin-left: calc((100% - 690rpx) / 2);
		/* background-image: linear-gradient(180deg,rgba(61, 132, 243, .1),rgba(61, 132, 243, 0) 100%); */
		background-color: #FFFFFF;
		position: relative;
		flex-direction: column;
		justify-content: space-between;
		border-radius: 16rpx;
	}

	.list_item_bg {
		position: absolute;
		left: 0;
		top: 0;
		width: 690rpx;
		height: 84rpx;
		background: linear-gradient(90deg, #0660EE 0%, rgba(158, 196, 255, 0) 100%);
		opacity: 0.1;
	}



	.l_list_header {
		width: 690rpx;
		height: 84rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 0 20rpx;
	}

	.l_list_content {
		width: 690rpx;
		min-height: 176rpx;
		display: flex;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 22rpx 20rpx 30rpx;
	}

	.l_list_icon {
		flex-shrink: 0;
		width: 40rpx;
		height: 40rpx;
		margin-right: 18rpx;
	}

	.l_list_h {
		max-width: 300rpx;
		line-height: 34rpx;
		font-size: 32rpx;
		color: #333333;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-weight: bold;
	}

	.l_list_h2 {
		width: 316rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		height: 32rpx;
		line-height: 32rpx;
		position: relative;
		font-size: 28rpx;
		color: #646B75;
		white-space: nowrap;

	}

	.l_list_inner {
		width: 314rpx;
		min-height: 120rpx;
		background: #ECF3FE;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		box-sizing: border-box;
		padding: 20rpx;
		display: flex;
	}

	.l_list_t {
		flex: 1;
		word-break: break-all;
		color: #646B75;
		font-size: 26rpx;
	}
</style>